#pragma once

#include <d3dx9.h>
#include "Object.h"
#include "GameDefines.h"

class CGame;

struct RayData
{
	D3DXVECTOR3 _ori, _dir;
};

class Camera :
	public Object, public MouseEventListener, public KeyEventListener
{
public:
	Camera(CGame* game);
	virtual ~Camera(void);

	virtual bool Tick();
	virtual bool PrepareRender();

	// mouse event listener
	virtual void MouseEventMove(MouseEvent& evt);
	virtual void MouseEventClick(MouseEvent& evt);
	virtual void MouseEventWheel(MouseEvent& evt);
	
	// Keyboard event listener
	virtual void KeyEventMsg(KeyEvent& evt);

	void SetMatrices();

	float GetCamDist() { return mCamDist; }
	void SetCamDist(float val) { mCamDist = val; }
	
	float GetDegree() { return mDegree; }
	void SetDegree(float val) { mDegree = val; }

	RayData GetPickRay();

private:
	float mCamDist;
	float mDegree;

	D3DXVECTOR3 mPitchYawRoll;
	D3DXVECTOR3 mPitchYawRollLast;
	D3DXVECTOR3 mPos;
	D3DXVECTOR3 mPosLast;

	int mMouseX;
	int mMouseY;
	int mDragStartX;
	int mDragStartY;

	bool mMouseRotateClicked;
	bool mMouseMoveClicked;
};

